//
//  PhotoBaseAppDelegate.m
//  PhotoBase
//
//  Created by Alec Flett on 11/16/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "PhotoBaseAppDelegate.h"
#import "MainViewController.h"
#import "CocoaTouch/FreebaseStatus.h"

#import "FBCache.h"

@implementation PhotoBaseAppDelegate


@synthesize window;
@synthesize mainViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    [self initDefaults];
	MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
	self.mainViewController = aController;
	[aController release];
	
    //NSLog(@"attaching cache to %@", [NSURLCache sharedURLCache]);
    NSLog(@"Existing cache has %d disk, %d memory", [[NSURLCache sharedURLCache] diskCapacity], [[NSURLCache sharedURLCache] memoryCapacity]);
    NSUInteger memoryCapacity = [[NSURLCache sharedURLCache] memoryCapacity];
    NSURLCache *sharedCache = [[FBCache alloc] initWithMemoryCapacity:memoryCapacity 
                                                         diskCapacity:10*1024*1024
                                                             diskPath:nil];
    
    [NSURLCache setSharedURLCache:sharedCache];
    [sharedCache release];
    
    FreebaseStatus* status = [[FreebaseStatus alloc] init];
    [[FreebaseSession session] addSessionDelegate:status];
    [status release];
    
    NSLog(@"New cache has %d disk, %d memory", [[NSURLCache sharedURLCache] diskCapacity], [[NSURLCache sharedURLCache] memoryCapacity]);
    
    
    mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
	[window addSubview:[mainViewController view]];
    [window makeKeyAndVisible];
    
    
    
    return YES;
}

- (void)initDefaults
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSDictionary *appDefaults = [NSDictionary
                                 
                                 dictionaryWithObject:@"NO" forKey:@"freebase.use_sandbox"];
    
    
    
    [defaults registerDefaults:appDefaults];
}

- (void)dealloc {
    [mainViewController release];
    [window release];
    [super dealloc];
}

@end
